package com.felix.ocoupon.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @author hsufelix
 * @email hsufelix@yeah.net
 * @Date 2020/11/11
 * <h1>有效期类型</h1>
 */

@Getter
@AllArgsConstructor
public enum PeriodType {

    REGULAR("固定的(固定日期)", 1),
    SHIFT("变动的(以领取之日开始计算算)", 2);

    private String description;

    private Integer code;

    public static PeriodType of (Integer code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(
                        code + "not exists"
                ));
    }
}
